﻿Public Class xtf_COPIARsoldadura
    Dim obj_soldadura As cls_soldadura_
    Public frm_listado As Form = Nothing

    Dim nactual As String = "0"
    Dim max As Integer = 0
    Dim min As Integer = 0
    Public Sub New(ByVal soldadura As cls_soldadura_, ByRef listado As Form)

        ' This call is required by the designer.
        InitializeComponent()
        Try
            frm_listado = listado
            Me.Text = "Copiar Soldaduras"
            obj_soldadura = soldadura
            If Not IsNothing(obj_soldadura.isometrico) Then
                txt_codigoInicial.Text = obj_soldadura.isometrico.codigo & "-" & Format(obj_soldadura.numeracion1Xidisometrico(obj_soldadura.idisometrico), "000")
            Else
                txt_codigoInicial.Text = obj_soldadura.codigo
            End If

            Dim maxchar As String = ""
            ' Add any initialization after the InitializeComponent() call.
            Dim mask As String = ""
            For Each Chr As Char In txt_codigoInicial.Text
                If Not IsNumeric(Chr) Then
                    mask &= Chr.ToString
                Else
                    nactual &= Chr
                    mask &= "0"
                    maxchar &= "9"
                End If
            Next
            txt_codigoFinal.Properties.Mask.EditMask = mask
            txt_codigoFinal.Text = Int(nactual) + txt_copias.Text

            max = Int(maxchar) - Int(nactual)

        Catch ex As Exception
            ErrManagerShow("Copiar soldaduras", "El código de la soldadura no es apto para realizar copias.", xtf_ErrManagerAlerta.errManagerImg.img_Error, xtf_ErrManagerAlerta.errManagerBtn.btn_Aceptar)
        End Try
    End Sub

    Private Sub txt_copias_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_copias.EditValueChanged
        If Me.Visible Then
            txt_codigoFinal.Text = Int(nactual) + txt_copias.Text
        End If

    End Sub

    Private Sub txt_copias_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles txt_copias.EditValueChanging
        If e.NewValue < min Or e.NewValue > Int(max) Then
            e.Cancel = True
        End If
    End Sub

    Private Sub btn_Guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Guardar.Click
        For i As Integer = 1 To txt_copias.Text
            txt_codigoFinal.Text = Int(nactual) + i
            obj_soldadura.codigo = txt_codigoFinal.Text
            obj_soldadura.numeracion1 = Int(nactual) + i
            obj_soldadura.Nuevo(True)
            If frm_listado.Visible Then
                CType(frm_listado, xtf_ABMsoldadura_).AgregarItem(obj_soldadura)
            End If
        Next
        Me.Close()
    End Sub
End Class